<%@ page language="java" contentType="text/xml; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.Character"%>
<%
	DAO dao = DAO.getInstance();
	Character c = null;
	
	int tired;
	int stamina;
	int delta;
	
	c = dao.getCharacter(Integer.parseInt(session.getAttribute("charNo").toString()));
	tired = c.getTired();
	if(tired > 0) {
		stamina = c.getProperty().getStamina();
		if(stamina > 30) {
			delta = 20;
		} else if(stamina <= 30 && stamina > 20) {
			delta = 15;
		} else if(stamina <= 20 && stamina > 10){
			delta = 10;
		} else {
			delta = 5;
		}
		System.out.println("Tired Before update " + tired);
		tired = tired - delta;
		
		if(tired <= 0) {
			tired = 0;
		}
		System.out.println("TiredUpdateResult : " + tired);
	
		out.println("<messages>");
		if(dao.setCharacterTired(tired, Integer.parseInt(session.getAttribute("charNo").toString()))) {
			String xmls = "";
			xmls += "<message delta=\"" + tired + "\"";
			//xmls += " chatCD=\"" + msgs[i].getChatCd() +"\">";
			xmls += ">";
			xmls += tired + "</message>";
			out.println(xmls);
			System.out.println(xmls);
		}
		out.println("</messages>");
	} else {
		out.println("<messages></messages>");
	}
%>